#  Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
#  Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
#  Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
#  Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
#  Vestibulum commodo. Ut rhoncus gravida arcu.
#  Xiaosi Artificial Intelligence Copyright reserved/No tampering or code theft allowed
#  Powered by Xiaosi Artificial Intelligence on Shao zong xian
from concurrent.futures import ThreadPoolExecutor

import numpy as np
import json
import pyttsx3 as p3
import requests
# 优化算法
def optimized_algorithm(array):
    return np.sum(array)  # 使用NumPy进行快速求和
def optimized_algorithon(array):
    return np.sum(bytearray)

# 使用多线程
def run_concurrently(functions, args):
    with ThreadPoolExecutor() as executor:
        results = list(executor.map(lambda f: f(*args), functions))
    return results
print('|----------------------------------------------------------------------------------------------|')
print('\033[1;31;43m|     ::::-++++++++++++-         .::::-++++++++++++:      .:::-==+++************++++=          |\033[0m')
print('\033[1;31;43m|      :----+***********=       .----=*********+*+.    .:---=++***++++++++++++++++**+          |\033[0m')
print('\033[1;31;43m|       .----=+*++++++++*+.    :----=*+++++++++*-     -----+**++++++++***********++*=          |\033[0m')
print('\033[1;31;43m|         :----+*++++++++*+:  :----+*++++++++*+:     -----+*++++++++*++========+++**=          |\033[0m')
print('\033[1;31;43m|          :----=*++++++++**-:----+*++++++++*=.     .-----*++++++++*-             ...          |\033[0m')
print('\033[1;31;43m|           .----=+*++++++++*+--=+*+++++++**-       :----=*+++++++*+                           |\033[0m')
print('\033[1;31;43m|             :----+*++++++++*+=*++++++++*+:        :----=*+++++++++-                          |\033[0m')
print('\033[1;31;43m|              :----=*++++++++**++++++++*=          .-----+*++++++++*++=-:..                   |\033[0m')
print('\033[1;31;43m|               .----=+*+++++++++++++++*-            :----=+*+++++++++******++=-:.             |\033[0m')
print('\033[1;31;43m|                 :----+*++++++++++++++.              .:----++***++++++++++++****++-           |\033[0m')
print('\033[1;31;43m|                .----=++++++++++++++++-                 .:::-==++*******+++++++++**+:         |\033[0m')
print('\033[1;31;43m|               :----+*++++++++++++++++*+.                     ..::-===+++**++++++++**.        |\033[0m')
print('\033[1;31;43m|             .----=+*++++++++**++++++++**-                          .:---=+*++++++++*-        |\033[0m')
print('\033[1;31;43m|            :----=**++++++++*==+*++++++++*=                          .-----+*+++++++*=        |\033[0m')
print('\033[1;31;43m|           :----+*++++++++*+=---+*++++++++*+.                        .-----+*+++++++*=        |\033[0m')
print('\033[1;31;43m|         .----=+*++++++++*=.:----+*++++++++**-     ::...-=-:...     .----=+*++++++++*:        |\033[0m')
print('\033[1;31;43m|        :----=*+++++++++*=   .----=*+++++++++*=    -----+******++++++++++**++++++++*+         |\033[0m')
print('\033[1;31;43m|       :----+*++++++++**:     .----=+*++++++++*+:  -----++++++++***+++*++++++++++**=          |\033[0m')
print('\033[1;31;43m|    .----=**+******+*+.        -----+*+******+**- -----+***+++++++++++++++*****+=:            |\033[0m')
print('\033[1;31;43m|    :-::-=+++++++++++=           ::::-=++++++++++*+:::::=++++++**********++++=-:              |\033[0m')
print('\033[1;31;43m|----------------------------------Xiao_Si_AI_NEXT_开发者_Beta版--------------------------------|\033[0m')
print('\033[1;31;43m|----------------------------------Xiao_Si_AI_NEXT Developer Beta Version---------------------|\033[0m')
print('\033[1;31;40m|----------------------------------你好，我是 Xiao_Si_AI_NEXT-------------------------------------|\033[0m')
print('\033[1;36m     - > Xiaosi Artificial Intelligence Program < -\033[0m')
print('\033[1;31m            -- 版本所有权 -- 更新查看网址 -- \033[0m')
print('\033[1;31m = > https://gitee.com/dirde12078904/xiao-si/releases < =\033[0m')
API_KEY =  '2iU0QJiVJBQqCKOLW5Jf8aS9'
SECRET_KEY = 'Aqg401HImuqRaprlpctYDLO1TnkClH6c'

def main():
    print('\033[1;36m作为你的智能伙伴，我既能写文案、想点子，又能陪你聊天、答疑解惑\033[0m')
    print('         请输入你想问的问题(注：什么问题不问,直接回车及为退出)')
    print("+=+=+=++=+=+=++=+=+=+说出你的问题+=+=+=+=+=+=+=+=+=++=+=+=+")
    url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token=" + get_access_token()
    while 1:
        s = input()
        # 注意message必须是奇数条
        payload = json.dumps({
            "messages": [
                {
                    "role": "user",
                    "content": s
                }
            ]
        })
        headers = {
            'Content-Type': 'application/json'
        }

        res = requests.request("POST", url, headers=headers, data=payload).json()
        print("\033[33mXiao Si AI\033[0m")
        print(res['result'])
        print('\033[31;5m  = = = = = = = = > 内容由AI生成，无法确保真实准确，仅供参考 < = = = = = = = = =\033[0m\r\n')
        print('请输入你想问的问题(注：什么问题不问,直接回车为退出)')
        print("+=+=+=++=+=+=++=+=+=+说出你的问题+=+=+=+=+=+=+=+=+=++=+=+=+")


def get_access_token():
    url = "https://aip.baidubce.com/oauth/2.0/token"
    params = {"grant_type": "client_credentials", "client_id": API_KEY, "client_secret": SECRET_KEY}
    return str(requests.post(url, params=params).json().get("access_token"))


if __name__ == '__main__':
    main()